home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_PrintBoxLine.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  4KB  |  186 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. VOID __regargs
  10. LTP_PrintLine(LayoutHandle *handle,UBYTE alignType,LONG left,LONG top,LONG space,STRPTR line,LONG len)
  11. {
  12.     struct RastPort     *rp;
  13.     LONG             width;
  14.     struct TextExtent     extent;
  15.  
  16.     rp    = &handle -> RPort;
  17.     len    = TextFit(rp,line,len,&extent,NULL,1,space,32767);
  18.     width    = extent . te_Width;
  19.  
  20.     if(len)
  21.     {
  22.         LTP_SetPens(rp,handle -> TextPen,handle -> BackgroundPen,JAM2);
  23.  
  24.         if(alignType == ALIGNTEXT_CENTERED)
  25.         {
  26.             LTP_PlaceText(handle,line,len,left + (space - width) / 2,top + handle -> RPort . TxBaseline);
  27.  
  28.             if(width < space)
  29.             {
  30.                 LONG fill;
  31.  
  32.                 LTP_SetAPen(rp,handle -> BackgroundPen);
  33.  
  34.                 if((fill = (space - width) / 2) > 0)
  35.                     RectFill(rp,left,top,left + fill - 1,top + handle -> RPort . TxHeight - 1);
  36.  
  37.                 if((fill = space - ((space - width) / 2)) > 0)
  38.                     RectFill(rp,left + fill,top,left + space - 1,top + handle -> RPort . TxHeight - 1);
  39.             }
  40.         }
  41.         else
  42.         {
  43.             if(alignType == ALIGNTEXT_LEFT)
  44.             {
  45.                 LTP_PlaceText(handle,line,len,left,top + handle -> RPort.TxBaseline);
  46.  
  47.                 if(left + width <= left + space - 1)
  48.                 {
  49.                     LTP_SetAPen(rp,handle -> BackgroundPen);
  50.  
  51.                     RectFill(rp,left + width,top,left + space - 1,top + handle -> RPort . TxHeight - 1);
  52.                 }
  53.             }
  54.             else
  55.             {
  56.                 LTP_PlaceText(handle,line,len,left + space - width,top + handle -> RPort . TxBaseline);
  57.  
  58.                 if(width < space)
  59.                 {
  60.                     LTP_SetAPen(rp,handle -> BackgroundPen);
  61.                     RectFill(rp,left,top,left + space - width - 1,top + handle -> RPort . TxHeight - 1);
  62.                 }
  63.             }
  64.         }
  65.     }
  66.     else
  67.     {
  68.         LTP_SetAPen(rp,handle -> BackgroundPen);
  69.         RectFill(rp,left,top,left + space - 1,top + handle -> RPort . TxHeight - 1);
  70.     }
  71. }
  72.  
  73.  
  74. /*****************************************************************************/
  75.  
  76.  
  77. VOID __regargs
  78. LTP_PrintLinePadded(LayoutHandle *Handle,LONG Left,LONG Top,LONG Space,STRPTR Line,LONG Len)
  79. {
  80.     struct RastPort *RPort    = &Handle -> RPort;
  81.     LONG         Size    = 0;
  82.     LONG         Start    = 0;
  83.     LONG         Count    = 0;
  84.     LONG         i    = 0;
  85.     LONG         Width    = 0;
  86.  
  87.     while(i < Len && Line[i] == ' ')
  88.     {
  89.         Size++;
  90.         i++;
  91.     }
  92.  
  93.     while(i < Len)
  94.     {
  95.         while(i < Len && Line[i] != ' ')
  96.         {
  97.             Size++;
  98.             i++;
  99.         }
  100.  
  101.         Width += TextLength(RPort,&Line[Start],Size);
  102.  
  103.         Count++;
  104.  
  105.         while(i < Len && Line[i] == ' ')
  106.             i++;
  107.  
  108.         Start    = i;
  109.         Size    = 0;
  110.     }
  111.  
  112.     if(Width)
  113.     {
  114.         LONG j;
  115.  
  116.         Space -= Width;
  117.  
  118.         j = Start = Size = 0;
  119.  
  120.         while(j < Len && Line[j] == ' ')
  121.         {
  122.             Size++;
  123.             j++;
  124.         }
  125.  
  126.         LTP_SetPens(RPort,Handle -> TextPen,Handle -> BackgroundPen,JAM2);
  127.         Move(RPort,Left,Top + RPort -> TxBaseline);
  128.  
  129.         Count--;
  130.  
  131.         for(i = 0 ; i <= Count ; i++)
  132.         {
  133.             if(i)
  134.             {
  135.                 LONG Delta;
  136.  
  137.                 if(Delta = (Space * i) / Count - (Space * (i - 1)) / Count)
  138.                 {
  139.                     LTP_SetAPen(RPort,Handle -> BackgroundPen);
  140.                     RectFill(RPort,RPort -> cp_x,Top,RPort -> cp_x + Delta - 1,Top + RPort -> TxHeight - 1);
  141.  
  142.                     LTP_SetAPen(RPort,Handle -> TextPen);
  143.                     Move(RPort,RPort -> cp_x + Delta,RPort -> cp_y);
  144.                 }
  145.             }
  146.  
  147.             while(j < Len && Line[j] != ' ')
  148.             {
  149.                 Size++;
  150.                 j++;
  151.             }
  152.  
  153.             Text(RPort,&Line[Start],Size);
  154.  
  155.             while(j < Len && Line[j] == ' ')
  156.                 j++;
  157.  
  158.             Start = j;
  159.             Size = 0;
  160.         }
  161.     }
  162.     else
  163.     {
  164.         LTP_SetAPen(RPort,Handle -> BackgroundPen);
  165.         RectFill(RPort,Left,Top,Left + Space - 1,Top + RPort -> TxHeight - 1);
  166.     }
  167. }
  168.  
  169.  
  170. /*****************************************************************************/
  171.  
  172.  
  173. VOID __regargs
  174. LTP_PrintBoxLine(LayoutHandle *handle,ObjectNode *node,LONG index)
  175. {
  176.     if(node -> Special . Box . Lines && node -> Special . Box . Lines[index])
  177.     {
  178.         LONG len = strlen(node -> Special . Box . Lines[index]);
  179.  
  180.         if(node -> Special . Box . AlignText == ALIGNTEXT_PAD)
  181.             LTP_PrintLinePadded(handle,node -> Left + 4,node -> Top + 2 + index * handle -> RPort . TxHeight,node -> Width - 8,node -> Special . Box . Lines[index],len);
  182.         else
  183.             LTP_PrintLine(handle,node -> Special . Box . AlignText,node -> Left + 4,node -> Top + 2 + index * handle -> RPort . TxHeight,node -> Width - 8,node -> Special . Box . Lines[index],len);
  184.     }
  185. }
  186.